package com.ydgk.service.impl;

import com.ydgk.bean.Furniture;
import com.ydgk.dao.*;
import com.ydgk.service.FurnitureService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.sql.Timestamp;
import java.util.List;
import java.util.Map;

@Service
public class FurnitureServiceImpl implements FurnitureService{
    @Autowired
    private FurnitureMapper furnitureMapper;

    @Autowired
    private Pre_orderMapper pre_orderMapper;

    @Autowired
    private ViewMapper viewMapper;

    @Autowired
    private DetailMapper detailMapper;

    @Autowired
    private FurnitureKindsMapper furnitureKindsMapper;

    public int insert(Furniture furniture) {
        return furnitureMapper.insert(furniture);
    }

    public List<Furniture> findAll(Map<String, Object> factorMap) {
        return furnitureMapper.findAll(factorMap);
    }

    public int findAllCount(Map<String, Object> factorMap) {
        return furnitureMapper.findAllCount(factorMap);
    }

    public Furniture findById(int fid) {
        return furnitureMapper.findById(fid);
    }

    public int deleteById(int fid) {
        int i = pre_orderMapper.findCountByFid(fid);
        if(i > 0){
             return 0;
        }else{
            viewMapper.deleteByFid(fid);
            detailMapper.deleteByFid(fid);
            furnitureKindsMapper.deleteByFid(fid);
            return furnitureMapper.deleteById(fid);
        }
    }

    public void setCondition(int fid,int val) {
        furnitureMapper.setCondition(fid,val,new Timestamp(System.currentTimeMillis()));
    }

    public int updateById(Furniture furniture) {
        return furnitureMapper.updateById(furniture);
    }

}
